import requestMeeting, { request } from '@/plugins/axios'
import { IRoomConfigInfo, IUserDomain, IVirtualRoomItem, VirtualRoomParams, SaveVirtualRoom } from './interface'
/** 获取资源信息 */
export const fetchLoadVirtualResource = async () =>
	request<{ list: IRoomConfigInfo[] }>({
		url: '/virtual_meeting_rooms/load_resource',
		method: 'get',
	}).then((res) => res)

/** 获取虚拟会议室列表 */
export const fetchLoadVirtualRoomList = async (params: VirtualRoomParams) =>
	request<{ list: IVirtualRoomItem[]; total: number }>({
		url: '/virtual_meeting_rooms/load_resource_list',
		method: 'get',
		params: params,
	}).then((res) => res)

/** 删除虚拟会议室 */
export const fetchDeleteVirtualRoom = async (ids: string[]) =>
	requestMeeting({
		url: '/virtual_meeting_rooms',
		method: 'delete',
		data: JSON.stringify(ids),
	}).then((res) => res)

/** 获取某虚拟会议室信息 */
export const fetchGetVirtualRoom = async (moid: string) =>
	request<IVirtualRoomItem>({
		url: '/virtual_meeting_rooms/' + moid,
		method: 'get',
	}).then((res) => res)

/** 请求所有用户域 */
export const fetchGetDomain = async (name: string) =>
	requestMeeting<IUserDomain[]>({
		url: '/all_user_domain',
		method: 'get',
		params: { name },
	}).then((res) => (res.success && res.data ? res.data : undefined))

/** 获取某虚拟会议室信息 */
export const fetchCheckVirtualRoomNameExisted = async (name: string, moid: string) =>
	requestMeeting<0 | 1>({
		url: '/virtual_meeting_rooms/valid_conf_name',
		method: 'GET',
		params: { vmr_name: name, vmr_id: moid },
	}).then((res) => (res.success ? res.data : true))

/** 获取某虚拟会议室信息 */
export const fetchSaveVirtualRoom = async (data: SaveVirtualRoom) =>
	requestMeeting<0 | 1>({
		url: '/virtual_meeting_rooms/' + data.vmr_moid,
		method: 'POST',
		data: data,
	}).then((res) => res)
